package com.bpms.servlet;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.bpms.common.VO;
import com.service.devimonitor.AtmpDeviceTypeImpl;
import com.service.devimonitor.Atmpcmdjbserviceimpl;
import com.service.devimonitor.Atmpdeviceserviceimpl;
import com.service.devimonitor.Atmpdevicestatusserviceimpl;
import com.service.util.DateUtil;
import com.service.util.StringUtil;
import com.zk.atm.forms.AtmpDeviceStatusForm;
import com.zk.atm.forms.AtmpDeviceTypeForm;
import com.zk.atm.utils.ConstantsAtmp;
import com.zk.atm.utils.ExcelExportUtil;
import com.zk.atm.utils.FileUtil;
import com.zk.atm.utils.JsonUtil;
import com.zk.atm.vo.AtmpDeviceTypeChildren;

public class BaseServlet extends HttpServlet {
    public static final Logger logger=Logger.getLogger(BaseServlet.class);
    private Atmpdevicestatusserviceimpl atmpdevicestatusserviceimpl;
	
    private Atmpdeviceserviceimpl atmpDeviceServiceImpl;
    
    private AtmpDeviceTypeImpl atmpDeviceTypeImpl;
    
    private Atmpcmdjbserviceimpl atmpcmdjbserviceimpl;
    
	public Atmpdevicestatusserviceimpl getAtmpdevicestatusserviceimpl() {
		if(this.atmpdevicestatusserviceimpl==null){
			this.atmpdevicestatusserviceimpl=new Atmpdevicestatusserviceimpl();
		}
		return this.atmpdevicestatusserviceimpl;
	}
	
	public Atmpdeviceserviceimpl getAtmpDeviceServiceImpl() {
		if(this.atmpDeviceServiceImpl==null){
			this.atmpDeviceServiceImpl=new Atmpdeviceserviceimpl();
		}
		return this.atmpDeviceServiceImpl;
	}
	
	public AtmpDeviceTypeImpl getAtmpDeviceTypeImpl() {
		if(this.atmpDeviceTypeImpl==null){
			this.atmpDeviceTypeImpl=new AtmpDeviceTypeImpl();
		}
		return this.atmpDeviceTypeImpl;
	}

	public Atmpcmdjbserviceimpl getAtmpcmdjbserviceimpl()
	{
		if (atmpcmdjbserviceimpl == null)
			atmpcmdjbserviceimpl = new Atmpcmdjbserviceimpl();
		return atmpcmdjbserviceimpl;
	}
	
	public VO getVo(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		VO args = new VO();
	    try {
			String m=StringUtil.getPropertyValue(request.getParameter("m"));
//			String r=StringUtil.getPropertyValue(request.getParameter("r"));
//			String s=StringUtil.getPropertyValue(request.getParameter("s"));
//			String t=StringUtil.getPropertyValue(request.getParameter("t"));
//			String u=StringUtil.getPropertyValue(request.getParameter("u"));
//			args.setAttr("m", m);
//			args.setAttr("r", r);
//			args.setAttr("s", s);
//			args.setAttr("t", t);
//			args.setAttr("u", u);
			Enumeration arg_array=request.getParameterNames();
			while(arg_array.hasMoreElements()){
				String arg_key=arg_array.nextElement().toString();
				String value=StringUtil.getPropertyValue(request.getParameter(arg_key));
				if(m.equals(ConstantsAtmp.ATMP_DEVICE_TRADE_EXPORT)&&arg_key.equals("org_name")){
					 value=new String(new String(value.getBytes("iso-8859-1"),"GBK"));
				}
				//System.out.println("***********************args:"+arg_key+",value="+value);
				args.setAttr(arg_key, value);
			}
			if(logger.isDebugEnabled()){
				System.out.println("BaseServlet:getVO:***********args="+args);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return args;

	}
	
	/**
	 * @author zengqun
	 * @remark 查询atmp_device_status_current表的状态数据
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void status_list(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceStatusForm statusForm=new AtmpDeviceStatusForm();
		try {
			String device_name=StringUtil.getPropertyValue(request.getParameter("device_name")).trim();
			String deviceip=StringUtil.getPropertyValue(request.getParameter("deviceip")).trim();
			String servicestatus=StringUtil.getPropertyValue(request.getParameter("servicestatus")).trim();
			String networkcode=StringUtil.getPropertyValue(request.getParameter("networkcode")).trim();
			String userid=StringUtil.getPropertyValue(request.getParameter("userid")).trim();
			statusForm.getCurrentVo().setDevice_name(device_name);
			statusForm.getCurrentVo().setDeviceip(deviceip);
			statusForm.getCurrentVo().setServicestatus(servicestatus);
			statusForm.getCurrentVo().setNetworkcode(networkcode);
			statusForm.setUserid(userid);
			List list=this.getAtmpdevicestatusserviceimpl().getDeviceStatusList(statusForm);
			System.out.println("list.size()="+list.size()+"*************************list="+list);
			request.setAttribute("devmonitorList", list);
			request.getRequestDispatcher("devicemonitor/devMonitorXML.jsp").forward(request, response);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @author zengqun
	 * @remark 查询atmp_device设备表的数据
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_list(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceStatusForm statusForm=new AtmpDeviceStatusForm();
		try {
			String device_name=StringUtil.getPropertyValue(request.getParameter("device_name")).trim();
			String deviceip=StringUtil.getPropertyValue(request.getParameter("deviceip")).trim();
			String networkcode=StringUtil.getPropertyValue(request.getParameter("networkcode")).trim();
			String belong_org_name=StringUtil.getPropertyValue(request.getParameter("belong_org_name")).trim();
			String userid=StringUtil.getPropertyValue(request.getParameter("userid")).trim();
			statusForm.getDevice_vo().setDevice_name(device_name);
			statusForm.getDevice_vo().setDevice_ip(deviceip);
			statusForm.getDevice_vo().setBelong_org_code(networkcode);
			statusForm.getDevice_vo().setBelong_org_name(belong_org_name);
			statusForm.setUserid(userid);
			List list=this.getAtmpdevicestatusserviceimpl().getDeviceList(statusForm);
			System.out.println("list.size()="+list.size()+"*************************list="+list);
			request.setAttribute("devmonitorList", list);
			request.getRequestDispatcher("devicemonitor/deviceXML.jsp").forward(request, response);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @author zengqun
	 * @remark 查询atmp_device设备表的数据
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_save(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceStatusForm form=new AtmpDeviceStatusForm();
		try{
			form=this.getDeviceForm(request, form);
			VO vo=new VO();
			String device_ip=form.getDevice_vo().getDevice_ip();
			String device_id=form.getDevice_vo().getDevice_id();
			//如果是新增操作,则判断是否有重复的ip地址
			if(device_id.equals("")){
				boolean is_exists_deviceip=this.getAtmpDeviceServiceImpl().checkDeviceIPIsExsitsInAtmpDevice(form);
				if(is_exists_deviceip==true){
					vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "1");
					vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE,
							"当前IP"+device_ip+",在设备表中已经存在,请您重新输入IP地址!");
					String json=JsonUtil.getJsonObjectByBpmVo(vo);
					response.getWriter().write(json);
					return ;
				}
			}

			boolean is_success=this.getAtmpDeviceServiceImpl().saveAtmpDevice(form);
			String message="您输入的IP"+device_ip+",在数据库中已经存在,保存操作失败!";
			if(is_success==true){
				message="操作成功!";
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
			}
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, message);
			String json=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected AtmpDeviceStatusForm getDeviceForm(HttpServletRequest request,AtmpDeviceStatusForm form)
	            throws Exception{
		   if(form==null){
			   form=new AtmpDeviceStatusForm();
		   }
           try {
        	   String method=StringUtil.getPropertyValue(request.getParameter("m"));
        	   //如果是保存:新增或修改
        	   if(method.equals(ConstantsAtmp.ATMP_DEVICE_ACTION_SAVE_METHOD)){

       			String device_id=StringUtil.getPropertyValue(request.getParameter("device_id")).trim();
       			String device_name=StringUtil.getPropertyValue(request.getParameter("device_name")).trim();
       			String device_code=StringUtil.getPropertyValue(request.getParameter("device_code")).trim();
       			String device_ip=StringUtil.getPropertyValue(request.getParameter("device_ip")).trim();
       			
       			String belong_org_id=StringUtil.getPropertyValue(request.getParameter("belong_org_id")).trim();
       			String belong_org_name=StringUtil.getPropertyValue(request.getParameter("belong_org_name")).trim();
       			String provider_name=StringUtil.getPropertyValue(request.getParameter("provider_name")).trim();
       			
       			String device_type_id=StringUtil.getPropertyValue(request.getParameter("device_type_id")).trim();
       			String device_type_code=StringUtil.getPropertyValue(request.getParameter("device_type_code")).trim();
       			String device_type_name=StringUtil.getPropertyValue(request.getParameter("device_type_name")).trim();
       			
       			String update_user_id=StringUtil.getPropertyValue(request.getParameter("user_id")).trim();
       			String update_user_name=StringUtil.getPropertyValue(request.getParameter("user_name")).trim();
       			
       			form.getDevice_vo().setDevice_id(device_id);
       			form.getDevice_vo().setDevice_name(device_name);
       			form.getDevice_vo().setDevice_code(device_code);
       			form.getDevice_vo().setDevice_ip(device_ip);
       			
       			form.getDevice_vo().setBelong_org_id(belong_org_id);
       			form.getDevice_vo().setBelong_org_name(belong_org_name);
       			form.getDevice_vo().setProvider_name(provider_name);
       			
       			form.getDevice_vo().setDevice_type_id(device_type_id);
       			form.getDevice_vo().setDevice_type_code(device_type_code);
       			form.getDevice_vo().setDevice_type_name(device_type_name);
       			
       			if(device_id.equals("")){
       				//初次创建时,创建人也是修改人;当修改时,此时的创建人不变
       				String create_user_id=update_user_id;
       				String create_user_name=update_user_name;
       				form.getDevice_vo().setCreate_user_id(create_user_id.equals("")?null:new Long(create_user_id));
       				form.getDevice_vo().setCreate_user_name(create_user_name);
       			}
       			form.getDevice_vo().setUpdate_user_id(update_user_id.equals("")?null:new Long(update_user_id));
       			form.getDevice_vo().setUpdate_user_name(update_user_name);
                  
        	   }
        	   //如果是删除
        	   else{
        		   String device_ip=StringUtil.getPropertyValue(request.getParameter("device_ip")).trim();
       			   form.getDevice_vo().setDevice_ip(device_ip);
        	   }
           }catch(Exception e){
        	   e.printStackTrace();
           }
			return form;
	}
	
	/**
	 * @author zengqun
	 * @remark 查询atmp_device设备表的数据
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_del(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceStatusForm statusForm=new AtmpDeviceStatusForm();
		try {
			String device_ip=StringUtil.getPropertyValue(request.getParameter("device_ip")).trim();
			String device_id=StringUtil.getPropertyValue(request.getParameter("device_id")).trim();
			
			VO vo=new VO();
			if(device_ip.equals("")&&device_id.equals("")){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "参数值不能为空,不能执行删除设备的操作!");
				String json_str=JsonUtil.getJsonObjectByBpmVo(vo);
				response.getWriter().write(json_str);
				return;
			}
			statusForm.getDevice_vo().setDevice_ip(device_ip);
			statusForm.getDevice_vo().setDevice_id(device_id);
			//删除之前,先判断是否有级联引用
			boolean is_refer_status_current=this.getAtmpDeviceServiceImpl().checkDeviceReferStatusCurrent(statusForm);
			if(is_refer_status_current==true){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "当前IP为"+device_ip+"的设备,在设备状态表中有记录,不能执行删除操作!");
				String json=JsonUtil.getJsonObjectByBpmVo(vo);
				response.getWriter().write(json);
				return;
			}
			
			boolean is_success=this.getAtmpDeviceServiceImpl().deleteDeviceByDeviceIp(statusForm);
			String msg="操作失败!";
			if(is_success==true){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
				msg="操作成功!";
			}
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, msg);
			String json=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json);
			return;
			//this.device_list(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return;
	}
	
	/**
	 * @author zengqun
	 * @remark 查询atmp_device_type表的数据
	 * @date 2012-10-16
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_type_list(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceTypeForm form=new AtmpDeviceTypeForm();
		try {
            form=this.getDeviceTypeForm(request, form);			
			List list=this.getAtmpDeviceTypeImpl().getDeviceTypeList(form);
			System.out.println("list.size()="+list.size()+"*************************list="+list);
			request.setAttribute("devmonitorList", list);
			request.getRequestDispatcher("devicemonitor/deviceTypeXML.jsp").forward(request, response);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @author zengqun
	 * @remark atmp_device_type表 保存
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_type_save(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceTypeForm form=new AtmpDeviceTypeForm();
		try{
			form=this.getDeviceTypeForm(request, form);
			boolean is_success=this.getAtmpDeviceTypeImpl().saveAtmpDeviceType(form);
			VO vo=new VO();
			String message="操作失败!";
			if(is_success==true){
				message="操作成功!";
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
			}
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, message);
			String json=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @author zengqun
	 * @remark atmp_device_type表删除
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_type_del(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceTypeForm form=new AtmpDeviceTypeForm();
		try {
			String type_id=StringUtil.getPropertyValue(request.getParameter("type_id")).trim();
			if(type_id.equals("")){
				VO vo=new VO();
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "参数值不能为空,不能执行删除设备的操作!");
				String json_str=JsonUtil.getJsonObjectByBpmVo(vo);
				response.getWriter().write(json_str);
				return;
			}
			form.getDevice_type_vo().setType_id(type_id);
			//删除之前,先判断是否有级联引用
			boolean is_refer_status_current=this.getAtmpDeviceTypeImpl().checkTypeReferChildrenType(form);
			VO vo=new VO();
			if(is_refer_status_current==true){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "当前ID为"+type_id+"的设备类型,在设备子类型表中有记录,不能执行删除操作!");
			}
			
			boolean is_success=this.getAtmpDeviceTypeImpl().deleteDeviceTypeById(form);
			if(is_success==true){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "操作成功!");
			}
			String json=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json);
			//this.device_list(request, response);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return;
	}
	//获取typeForm
	protected AtmpDeviceTypeForm getDeviceTypeForm(HttpServletRequest request,AtmpDeviceTypeForm form)
	    throws Exception{
		String method=StringUtil.getPropertyValue(request.getParameter("m"));
		if(form==null){
			form=new AtmpDeviceTypeForm();
		}
		String type_code=StringUtil.getPropertyValue(request.getParameter("type_code")).trim();
		String type_name=StringUtil.getPropertyValue(request.getParameter("type_name")).trim();
		String type_id=StringUtil.getPropertyValue(request.getParameter("type_id")).trim();
		if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_SAVE)){
			String type_remark=StringUtil.getPropertyValue(request.getParameter("type_remark")).trim();
			form.getDevice_type_vo().setType_remark(type_remark);
		}else if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_DEL)){
			
		}
		form.getDevice_type_vo().setType_id(type_id);
		form.getDevice_type_vo().setType_name(type_name);
		form.getDevice_type_vo().setType_code(type_code);
		
		return form;
	}
	
	/**
	 * @author zengqun
	 * @remark 查询atmp_device_type表的数据
	 * @date 2012-10-16
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_type_children_list(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceTypeForm form=new AtmpDeviceTypeForm();
		try {
            form=this.getDeviceTypeChildrenForm(request, form);			
			List list=this.getAtmpDeviceTypeImpl().getDeviceTypeChildrenList(form);
			System.out.println("list.size()="+list.size()+"*************************list="+list);
			request.setAttribute("devmonitorList", list);
			request.getRequestDispatcher("devicemonitor/deviceTypeChildrenXML.jsp").forward(request, response);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @author zengqun
	 * @remark atmp_device_type表 保存
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_type_children_save(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceTypeForm form=new AtmpDeviceTypeForm();
		try{
			form=this.getDeviceTypeChildrenForm(request, form);
			boolean is_success=this.getAtmpDeviceTypeImpl().saveAtmpDeviceTypeChildren(form);
			VO vo=new VO();
			String message="操作失败!";
			if(is_success==true){
				message="操作成功!";
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
			}
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, message);
			String json=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @author zengqun
	 * @remark atmp_device_type表删除
	 * @date 2012-10-9
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void device_type_children_del(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AtmpDeviceTypeForm form=new AtmpDeviceTypeForm();
		try {
			String children_device_id=StringUtil.getPropertyValue(request.getParameter("children_device_id")).trim();
			String child_device_name_en_standby_column1=StringUtil.getPropertyValue(request.getParameter("standby_column1")).trim();
			if(children_device_id.equals("")){
				VO vo=new VO();
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "参数值不能为空,不能执行删除设备的操作!");
				String json_str=JsonUtil.getJsonObjectByBpmVo(vo);
				response.getWriter().write(json_str);
				return;
			}
			form.getDevice_type_children_vo().setChildren_device_id(children_device_id);
			form.getDevice_type_children_vo().setStandby_column1(child_device_name_en_standby_column1);
			//删除之前,先判断是否有级联引用
			boolean is_refer_status_current=this.getAtmpDeviceTypeImpl().checkChildrenReferStatusOriginal(form);
			VO vo=new VO();
			if(is_refer_status_current==true){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "当前ID为"+children_device_id+"的子设备,在设备状态表中有记录,不能执行删除操作!");
				String json=JsonUtil.getJsonObjectByBpmVo(vo);
				response.getWriter().write(json);
				return;
			}
			
			boolean is_success=this.getAtmpDeviceTypeImpl().deleteDeviceTypeChildrenById(form);
			if(is_success==true){
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "操作成功!");
			}
			String json=JsonUtil.getJsonObjectByBpmVo(vo);
			response.getWriter().write(json);
			//this.device_list(request, response);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return;
	}
	//获取typeForm
	protected AtmpDeviceTypeForm getDeviceTypeChildrenForm(HttpServletRequest request,AtmpDeviceTypeForm form)
	    throws Exception{
		String method=StringUtil.getPropertyValue(request.getParameter("m"));
		if(form==null){
			form=new AtmpDeviceTypeForm();
		}
		AtmpDeviceTypeChildren children=new AtmpDeviceTypeChildren();
		
		String children_device_id=StringUtil.getPropertyValue(request.getParameter("children_device_id")).trim();
		String child_device_code=StringUtil.getPropertyValue(request.getParameter("child_device_code")).trim();
		String child_device_name=StringUtil.getPropertyValue(request.getParameter("child_device_name")).trim();
		String child_device_name_cn=StringUtil.getPropertyValue(request.getParameter("child_device_name_cn")).trim();
		
		String type_id=StringUtil.getPropertyValue(request.getParameter("type_id")).trim();
		String type_name=StringUtil.getPropertyValue(request.getParameter("type_name")).trim();
		
		if(method.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_CHILDREN_SAVE)){
			String remark=StringUtil.getPropertyValue(request.getParameter("remark")).trim();
			children.setRemark(remark);
		}
		children.setChildren_device_id(children_device_id);
		children.setChild_device_code(child_device_code);
		children.setChild_device_name(child_device_name);
		children.setStandby_column2(child_device_name_cn);
		
		children.setType_id(type_id);
		children.setType_name(type_name);
		
		form.setDevice_type_children_vo(children);
		return form;
	}
	
	protected void export_trade_list(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String date_time = DateUtil.getDateFormat(new Date(), "yyyy-MM-dd");
		date_time = (new StringBuilder("trade_")).append(date_time).append(".xls").toString();
		String file_name = date_time;
		file_name=URLEncoder.encode(file_name, "UTF-8");
		VO args_vo = getVo(request, response);
		
		String file_url = (new StringBuilder(request.getRealPath("/"))).append("export").append("/").append(date_time).toString();
		args_vo.setAttr("file_url", file_url);
		args_vo.setAttr(ConstantsAtmp.ATMP_CMD_METHOD_KEY_NAME,ConstantsAtmp.ATMP_DEVICE_TRADE_EXPORT);
		
		VO result_vo = getAtmpcmdjbserviceimpl().exec(args_vo);
		ServletOutputStream out = response.getOutputStream();
		HSSFWorkbook book = null;
		try {
			book = (HSSFWorkbook) result_vo.getObj("hb");
			if (book == null) {
				book = ExcelExportUtil.getExcelBook(args_vo);
			}
			File file_excel = new File(file_url);
			if (file_excel.exists()) {
				file_excel.delete();
			}
			if (!file_excel.exists()) {
				FileUtil.createFile(file_url);
			}
			FileOutputStream fileout = new FileOutputStream(file_excel);
			if (book != null) {
				book.write(fileout);
			}
			fileout.close();
			response.setContentType("application/x-download;charset=UTF-8");
			response.setHeader("Content-Disposition", "attachment; filename=\""+file_name+"\"");
			FileInputStream fis = new FileInputStream(file_excel);
			BufferedInputStream bis = new BufferedInputStream(fis);
			byte b[] = new byte[1024];
			int k = 0;
			while ((k = bis.read(b)) != -1) {
				out.write(b, 0, k);
			}
			out.flush();
			out.close();
			bis.close();
			fis.close();
			return;
		} catch (Exception e) {
			e.printStackTrace();
		}
}
}
